/**
 * 
 * @authors youzhao.zhou@pandauu.com
 * @date    2016-09-08 15:12:44
 * @version $Id$
 * 
 * 车票兑换页
 * 
 */

;(function(root,factory){

  var dependent = {
    zepto : typeof exports !== 'undefined' ? require('./zepto.js')&&root.$ : root.$,
    underscore : typeof exports !== 'undefined' ? require('../../public_src/js/underscore/underscore.js') : root._,
    Project : typeof exports !== 'undefined' ? require('../../public_src/js/1_self/1_project.js') : root.Project,
    conf : typeof exports !== 'undefined' ? require('../../public_src/js/1_self/2_config.js') : root.conf,
    log : typeof exports !== 'undefined' ? require('../../public_src/js/1_self/3_log.js') : root.p_log,
    path: {
      zepto : '../../p_src/js/convert/zepto.js',
      underscore : '../../public_src/js/underscore/underscore.min',
      Project : '../../public_src/js/1_self/1_project',
      conf : '../../public_src/js/1_self/2_config',
      log : '../../public_src/js/1_self/3_log',
    }
  };
  
  if(typeof exports === 'object' && typeof module === 'object'){

    module.exports = factory(exports,
      dependent.zepto, 
      dependent.underscore,
      dependent.Project, 
      dependent.conf,
      dependent.log
    );

  } else if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.

    define(['exports', 
      dependent.path.zepto, 
      dependent.path.underscore,
      dependent.path.Project, 
      dependent.path.conf,
      dependent.path.log
      ], factory);
  } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
    // CommonJS
    factory(exports, 
      dependent.zepto, 
      dependent.underscore,
      dependent.Project, 
      dependent.conf,
      dependent.log
    );
  } else {
    // Browser globals
    if (!(dependent.Project||dependent.conf||dependent.log)) {
      throw('请加载相应的文件！');
    }
    factory({},
      dependent.zepto, 
      dependent.underscore,
      dependent.Project, 
      dependent.conf,
      dependent.log
    );
  }

})((typeof window !== 'undefined' ? window : this) ,function(exports,$ ,_ , Project, conf, log, undefined){
  'use strict';

  setTimeout(function(){

    if (typeof $ === 'undefined') {
      $ = window.$;
    }

    if (typeof _ === 'undefined') {
      _ = window._;
    }

    /*
      调试开关
    */
    log._logToggle(true);

    var urlConf = conf._conf;
    /*
      项目工具类对象
    */
    var project = new Project();

    var params = project.getQueryStringObj();
    /*
      设置导航头部
    */
    project.setHTML('.middle', '快捷回复列表');

    $('.service').attr({
      'data-id': params.thread_id
    });
    
    $.ajax({
      url: urlConf.apiRoot + urlConf.apiPre.one + urlConf.api.quickReplyList,
      type: 'GET',
      dataType: 'json'
    })
    .done(function(data) {
      if (data.code === 0) {
        $('.jsReplyContainer').html(_.template($('#replyTpl').html())({list: data.data}));
        log._log($('#jsReplyContainer'));
      }
      
    })
    .fail(function() {
      log._log("error");
    })
    .always(function() {
      log._log("complete");
    });
    addEvent();
    function addEvent(){
      var type = '';
      $('.jsQuickreply').on('click', function(event) {
        event.preventDefault();
        var target = $(event.target);
        var eventType = target.data('event');

        switch(eventType){
          case 'li':
            target.siblings(".select").removeClass('select');
            target.addClass('select');
            type = target.data('type')+'';
            break;
          case 'use':

          if (!type) {
            alert('请选择快捷回复');

            return false;
          }

          if (type === '1') {
            sendMsg();
          }else{
            sendImg();
          }

          $(target.data('clear')).removeClass('select');
          type = '';


            break;
        }


      });
    }

    /*
      发送图片
    */
    function sendImg(){

    }
    /*
      选择文字快捷回复
    */
    function sendMsg(){
      
    }

    window.addEventListener('unload',function(){
      log = null;
    },false);

  },0);

});
